package com.koron.sinoprobe.web.ledger.bean.query;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.koron.bean.query.PageQuery;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
@ApiModel(description = "专项管理-专项项目")
public class SpProjectQuery extends PageQuery {

    @ApiModelProperty("主键")
    private String id;

    @ApiModelProperty("计划id")
    private String planId;

    @ApiModelProperty("项目编码")
    private String code;

    @ApiModelProperty("名称/标题")
    private String name;

    @ApiModelProperty("重要程度：专项管理.important_level")
    private String importantLevel;

    @ApiModelProperty("主办部门")
    private String hostDeptId;

    @ApiModelProperty("主办部门名称")
    private String hostDeptName;

    @ApiModelProperty("创建部门")
    private String deptId;

    @ApiModelProperty("创建部门名称")
    private String deptName;

    @ApiModelProperty("状态集合：规划中、进行中、已完成")
    private List<String> status;

    @ApiModelProperty("当前里程碑")
    private String currMilestone;

    @ApiModelProperty("业务类别集合：规划中、进行中、已完成")
    private List<String> bizCategory;

    @ApiModelProperty("项目类别集合：规划中、进行中、已完成")
    private List<String> projectType;

    @ApiModelProperty("开始/结束计划完成时间，yyyy-mm-dd")
    private List<Date> planFinishTime;

    @ApiModelProperty("开始/结束创建时间，yyyy-mm-dd HH:mm")
    private List<Date> createTime;

    @ApiModelProperty("专项工程操作类型，字典：sp_project_action")
    private String projectAction;

    @ApiModelProperty("需要排除的id")
    private List<String> rids;

    @ApiModelProperty("设备ID集合")
    private List<String> equipmentIds;

    @ApiModelProperty("设备ID")
    private String equipmentId;

    @ApiModelProperty("设备名称")
    private String equipmentName;

    @JsonIgnore
    @ApiModelProperty(value = "删除标志, 默认查询变不删除的数据", hidden = true)
    private Boolean deleteFlag = false;

    @ApiModelProperty(value = "所属年份")
    private String belongYear;

    @ApiModelProperty(value = "状态")
    private String state;

    @ApiModelProperty("负责人账号")
    private String leader;

    @ApiModelProperty("负责人名字")
    private String leaderName;

    private String milestoneStatus;

    private String sqlState;

    public String setSqlState(String state){
        if (StrUtil.isEmpty(state)){
            return null;
        }
        StringBuilder sb = new StringBuilder();
        switch (state) {
            case "正常":
                sb.append("((milestone.fact_end_time is null and DATE(NOW()) <= DATE(milestone.expect_end_time)) \n" +
                        "    OR (milestone.fact_end_time is not null and DATE(milestone.fact_end_time) < DATE(milestone.expect_end_time) and DATE(milestone.update_time <= DATE(milestone.expect_end_time))))");
                break;
            case "滞后":
                sb.append("((milestone.fact_end_time IS NULL AND DATE(NOW()) > DATE(milestone.expect_end_time)) \n" +
                        "\tOR (milestone.fact_end_time IS NOT NULL AND DATE(milestone.fact_end_time) > DATE(milestone.expect_end_time)))");
                break;
            case "填报延期":
                sb.append("((milestone.fact_end_time is not null and DATE(milestone.fact_end_time) < DATE(milestone.expect_end_time)\n" +
                        "and DATE(milestone.update_time) > DATE(milestone.expect_end_time)))");
                break;
        }
        this.sqlState = sb.toString();
        return this.sqlState;
    }

    public String getSqlState() {
        return sqlState;
    }
}
